package com.mycompany.myapp.web.rest.controller;

import com.mycompany.myapp.service.CommentService;
import com.mycompany.myapp.service.dto.CommentDTO;
import com.mycompany.myapp.web.rest.utils.ResultObj;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.net.URISyntaxException;
import java.util.List;

@Api(tags = {"评论管理"})
@RestController
@RequestMapping("/api")
public class CommentController {

    private final CommentService commentService;

    public CommentController(CommentService commentService) {
        this.commentService = commentService;
    }

    @ApiOperation("添加留言 RequestBody")
    @PostMapping("/comment/create")
    public ResultObj createComment(@RequestBody CommentDTO commentDTO) throws URISyntaxException {
        return commentService.createComment(commentDTO);
    }

    @ApiOperation("根据商品Id查询评价")
    @GetMapping("/comment/select/commodityId")
    public ResultObj findByCommodityId(@RequestParam Long commodityId){
        return ResultObj.back(200,commentService.findByCommodityId(commodityId));
    }

    @ApiOperation("根据id删除评价")
    @DeleteMapping("/comment/id")
    public ResultObj deleteComment(@RequestParam List<Long> commentId){
        return commentService.deleteComments(commentId);
    }



}
